package com.university.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.university.mapper.MovieOrderMapper;
import com.university.pojo.cqe.command.CmdMovieOrder;
import com.university.pojo.cqe.command.CmdMovieReview;
import com.university.pojo.cqe.query.MovieQuery;
import com.university.pojo.dto.FoodOrderDTO;
import com.university.pojo.dto.MovieOrderAdminDTO;
import com.university.pojo.dto.MovieOrderUserDTO;
import com.university.pojo.entity.MovieOrder;
import com.university.service.MovieOrderService;
import com.university.utility.ObjectUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Date: 2021/5/15 18:05
 * @Description:
 */
@Service
public class MovieOrderServiceImpl implements MovieOrderService {

    @Resource
    private MovieOrderMapper movieOrderMapper;

    @Override
    public void saveMovieOrder(CmdMovieOrder cmdMovieOrder) {
        MovieOrder movieOrder = ObjectUtils.convert(cmdMovieOrder, MovieOrder.class);
        movieOrderMapper.insert(movieOrder);
    }

    @Override
    public List<MovieOrderUserDTO> userGetMovieOrder(MovieQuery query) {
        return movieOrderMapper.userGetMovieOrder(query);
    }

    @Override
    public IPage<MovieOrderAdminDTO> adminGetMovieOrder(MovieQuery query) {
        IPage<FoodOrderDTO> page = new Page<>(query.getPage(), query.getPageSize());
        return movieOrderMapper.adminGetMovieOrderPage(page, query);
    }

    @Override
    public void review(CmdMovieReview cmdMovieReview) {
        MovieOrder movieOrder = ObjectUtils.convert(cmdMovieReview, MovieOrder.class);
        movieOrderMapper.updateById(movieOrder);
    }
}
